package com.itheima.motorcycletype.controller;

import com.carkeeper.entity.PageResult;
import com.carkeeper.entity.Result;
import com.carkeeper.entity.StatusCode;
import com.github.pagehelper.Page;
import com.itheima.motorcycletype.pojo.Logo;
import com.itheima.motorcycletype.pojo.MotorcycleType;
import com.itheima.motorcycletype.service.LogoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/logo")
public class LogoController {

    @Autowired
    private LogoService logoService;


    /**
     * 分页查询
     * @param map
     * @return
     */
    @GetMapping("/findPage")
    public Result findPage(@RequestParam Map map){
        Page<Logo> LogoPage = logoService.selectAll(map);
        PageResult pageResult = new PageResult(LogoPage.getTotal(), LogoPage.getResult());
        return new Result(true, StatusCode.OK,"查询成功",pageResult);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public Result selectById(@PathVariable Integer id){
        Logo logo = logoService.selectById(id);
        return new Result(true,StatusCode.OK,"查询成功",logo);
    }

    /**
     * 添加车标
     * @param logo
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Logo logo){
        Integer add = logoService.add(logo);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /**
     * 修改车标
     * @param logo
     * @return
     */
    @PutMapping
    public Result update(@RequestBody Logo logo){
        Integer update = logoService.update(logo);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /**
     * 删除车标
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public Result delete(@PathVariable Integer id){
        Integer delete = logoService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /**
     * 搜索车标
     * @param searchMap
     * @return
     */
    @GetMapping("/logoSearch" )
    public Result logoSearch(@RequestParam Map searchMap){
        List<Logo> list = logoService.findList(searchMap);
        return new Result(true,StatusCode.OK,"查询成功",list);
    }

    /**
     * 根据车型搜索
     * @param searchMap
     * @return
     */
    @GetMapping("/motorcycleTypeSearch" )
    public Result motorcycleTypeSearch(@RequestParam Map searchMap){
        List<MotorcycleType> list = logoService.findListByMotorcycleType(searchMap);
        return new Result(true,StatusCode.OK,"查询成功",list);
    }
}
